package com.example.ykbboom.broadcastpractice;

import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

/**
 * @author ykbboom
 * @email ykbpro@whut.edu.cn
 * @time 2017-1-22 18:28:52
 * 功能: 发送广播
*/
public class MainActivity extends BaseActivity {

//    private LocalBroadcastManager localBroadcastManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        localBroadcastManager = LocalBroadcastManager.getInstance(this);//获取本地广播实例
        Button button = (Button) findViewById(R.id.offlinebtn);
        Button exitBtn = (Button) findViewById(R.id.exitbtn);
        final SharedPreferences sharedPreferences = getSharedPreferences("state",MODE_PRIVATE);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent("com.example.ykbboom.FORCE_OFFLINE");
                /*localBroadcastManager.*/sendBroadcast(intent);//发送广播
            }
        });
        exitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.clear();
                editor.apply();
//                Log.d("text","-----------"+sharedPreferences.getBoolean("login_state",false)+"0000000");
                Intent intent = new Intent(MainActivity.this,LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }
    }
